#include <vld.h>
#include <cstdcall/http_client.h>

using namespace cstdcall;

static int test_Get(http::ClientRef &client)
{
	error_t			err;

	auto resp = client->Get("https://www.baidu.com", err);
	if (resp == nullptr){
		printf(" err: %s\n", err->what());
		return 0;
	}
	printf("Url : %s\n", resp->Request_->Url.c_str());	

	for (auto it = resp->Header.begin(); it != resp->Header.end(); it++){
		printf("%s : %s\n", it->first.c_str(), it->second.c_str());
	}
	printf("content:%s\n", resp->Content.c_str());
	return 0;
}

static int test_Post(http::ClientRef &client)
{
	error_t			err;

	auto resp = client->Post("127.0.0.1:8080", http::ContentTypeJson, "{\"name\" : \"jinzhao\"}", err);
	if (resp == nullptr){
		printf(" err: %s\n", err->what());
		return 0;
	}
	printf("Url : %s\n", resp->Request_->Url.c_str());	

	for (auto it = resp->Header.begin(); it != resp->Header.end(); it++){
		printf("%s : %s\n", it->first.c_str(), it->second.c_str());
	}
	printf("content:%s\n", resp->Content.c_str());

	return 0;
}


//please run it with commond line
int main()
{

	auto httpClient = http::NewClient();

	printf("*********************GET********************\n");
	test_Get(httpClient);

	printf("********************POST*******************\n");
	test_Post(httpClient);
}